package com.rahwi.rahwi_server.Controller;

import com.rahwi.rahwi_server.DefineEntity.MainPostDetail;
import com.rahwi.rahwi_server.Handler.Security.Security;
import com.rahwi.rahwi_server.Service.impl.PostDetailService;
import com.rahwi.rahwi_server.vo.params.PageParams;
import com.rahwi.rahwi_server.vo.params.PostDetailParam;
import com.rahwi.rahwi_server.vo.params.RegisterParams;
import com.rahwi.rahwi_server.vo.results.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PostDetailController
 * @Description
 * @Date 2021/12/26 1:47
 * @Autor dn
 * @Version 1.0
 */
@RestController
@RequestMapping("/postdetail")
public class PostDetailController {

    @Autowired
    PostDetailService postDetailService;

    @PostMapping("/get")
    public ActionResult GetPostDetail(@RequestBody PostDetailParam postDetailParam){
        PageParams pageParams = new PageParams();
        pageParams.setPage(postDetailParam.getPage());
        return ActionResult.success(postDetailService.GetPostDetail(postDetailParam.getPid(),pageParams,postDetailParam.getUid(), postDetailParam.isOnly_owner()));
    }

    @PostMapping("/getpost")
    public ActionResult GetPost(@RequestParam(name = "pid")int Pid){
        MainPostDetail mainPostDetail = postDetailService.GetPostDetail(Pid);
        return mainPostDetail==null?ActionResult.fail(700,"未找到帖子"):ActionResult.success(mainPostDetail);
    }

    @Security
    @PostMapping("/likepost")
    public ActionResult LikePost(@RequestParam(name = "uid")int Uid,@RequestParam(name = "pid")int Pid){
        return ActionResult.success(postDetailService.LikePost(Pid,Uid));
    }

    @Security
    @PostMapping("/likecomment")
    public ActionResult LikeComment(@RequestParam(name = "uid")int Uid,@RequestParam(name = "cid")int Cid){
        return ActionResult.success(postDetailService.LikeComment(Cid,Uid));
    }

    @PostMapping("/showreplys")
    public ActionResult ShowReply(@RequestParam(name = "cid")int Cid, @RequestParam(name = "page")int Page, @RequestParam(name = "pagesize", defaultValue = "5", required = false)int PageSize){
        System.out.println("Cid:" + Cid + "Page:" + Page + "PageSize" + PageSize);
        return ActionResult.success(postDetailService.GetReplies(Page, PageSize, Cid));
    }
}
